#include <iostream>
using namespace std;
#include <cstring>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <pthread.h>
using namespace std;


int main()
{
  // create socket 
  int listen_sockfd = socket(AF_INET , SOCK_STREAM , 0);
  if (listen_sockfd < 0 )
  {
    cerr << "socket error" << endl;
    exit(1);
  }

  int opt = 1;
  setsockopt(listen_sockfd , SOL_SOCKET , SO_REUSEADDR , &opt , sizeof(opt));

  // bind 
  struct sockaddr_in local;
  memset(&local , '\0' , sizeof(local));
  local.sin_family = AF_INET; 
  local.sin_port = htons(8081);
  local.sin_addr.s_addr = INADDR_ANY;

  if (bind(listen_sockfd , (struct sockaddr*)&local , sizeof(local)) < 0 )
  {
    cerr << "bind error" << endl; 
    exit(2);
  }

  // listen 
  listen(listen_sockfd , 2);

  for(;;)
  {
    ;
  }
  return 0;
}
